; ModuleID = 'trap.c'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i386-pc-linux-gnu"

%struct.MPI_Status = type { i32, i32, i32, i32, i32 }
%struct.ompi_communicator_t = type opaque
%struct.ompi_datatype_t = type opaque
%struct.ompi_predefined_communicator_t = type opaque
%struct.ompi_predefined_datatype_t = type opaque

@ompi_mpi_comm_world = external global %struct.ompi_predefined_communicator_t
@ompi_mpi_float = external global %struct.ompi_predefined_datatype_t
@.str = private constant [38 x i8] c"With n = %d trapezoids, our estimate\0A\00", align 4
@.str1 = private constant [36 x i8] c"of the integral from %f to %f = %f\0A\00", align 4

define i32 @main(i32 %argc, i8** %argv) nounwind {
entry:
  %argc_addr = alloca i32, align 4
  %argv_addr = alloca i8**, align 4
  %retval = alloca i32
  %my_rank = alloca i32
  %p = alloca i32
  %a = alloca float
  %b = alloca float
  %n = alloca i32
  %h = alloca float
  %local_a = alloca float
  %local_b = alloca float
  %local_n = alloca i32
  %integral = alloca float
  %total = alloca float
  %source = alloca i32
  %dest = alloca i32
  %tag = alloca i32
  %status = alloca %struct.MPI_Status
  %"alloca point" = bitcast i32 0 to i32
  store i32 %argc, i32* %argc_addr
  store i8** %argv, i8*** %argv_addr
  store float 0.000000e+00, float* %a, align 4
  store float 1.000000e+00, float* %b, align 4
  store i32 1024, i32* %n, align 4
  store i32 0, i32* %dest, align 4
  store i32 0, i32* %tag, align 4
  %0 = call i32 @MPI_Init(i32* %argc_addr, i8*** %argv_addr) nounwind
  %1 = call i32 @MPI_Comm_rank(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), i32* %my_rank) nounwind
  %2 = call i32 @MPI_Comm_size(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), i32* %p) nounwind
  %3 = load float* %b, align 4
  %4 = load float* %a, align 4
  %5 = fsub float %3, %4
  %6 = load i32* %n, align 4
  %7 = sitofp i32 %6 to float
  %8 = fdiv float %5, %7
  store float %8, float* %h, align 4
  %9 = load i32* %p, align 4
  %10 = load i32* %n, align 4
  %11 = sdiv i32 %10, %9
  store i32 %11, i32* %local_n, align 4
  %12 = load i32* %my_rank, align 4
  %13 = load i32* %local_n, align 4
  %14 = mul nsw i32 %12, %13
  %15 = sitofp i32 %14 to float
  %16 = load float* %h, align 4
  %17 = fmul float %15, %16
  %18 = load float* %a, align 4
  %19 = fadd float %17, %18
  store float %19, float* %local_a, align 4
  %20 = load i32* %local_n, align 4
  %21 = sitofp i32 %20 to float
  %22 = load float* %h, align 4
  %23 = fmul float %21, %22
  %24 = load float* %local_a, align 4
  %25 = fadd float %23, %24
  store float %25, float* %local_b, align 4
  %26 = load float* %local_a, align 4
  %27 = load float* %local_b, align 4
  %28 = load i32* %local_n, align 4
  %29 = load float* %h, align 4
  %30 = call float @Trap(float %26, float %27, i32 %28, float %29) nounwind
  store float %30, float* %integral, align 4
  %31 = load i32* %my_rank, align 4
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %bb, label %bb5

bb:                                               ; preds = %entry
  %33 = load float* %integral, align 4
  store float %33, float* %total, align 4
  store i32 1, i32* %source, align 4
  br label %bb3

bb1:                                              ; preds = %bb3
  %integral2 = bitcast float* %integral to i8*
  %34 = load i32* %source, align 4
  %35 = load i32* %tag, align 4
  %36 = call i32 @MPI_Recv(i8* %integral2, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %34, i32 %35, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.MPI_Status* %status) nounwind
  %37 = load float* %integral, align 4
  %38 = load float* %total, align 4
  %39 = fadd float %38, %37
  store float %39, float* %total, align 4
  %40 = load i32* %source, align 4
  %41 = add nsw i32 %40, 1
  store i32 %41, i32* %source, align 4
  br label %bb3

bb3:                                              ; preds = %bb1, %bb
  %42 = load i32* %p, align 4
  %43 = load i32* %source, align 4
  %44 = icmp slt i32 %43, %42
  br i1 %44, label %bb1, label %bb4

bb4:                                              ; preds = %bb3
  br label %bb7

bb5:                                              ; preds = %entry
  %integral6 = bitcast float* %integral to i8*
  %45 = load i32* %dest, align 4
  %46 = load i32* %tag, align 4
  %47 = call i32 @MPI_Send(i8* %integral6, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %45, i32 %46, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  br label %bb7

bb7:                                              ; preds = %bb5, %bb4
  %48 = load i32* %my_rank, align 4
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %bb8, label %bb9

bb8:                                              ; preds = %bb7
  %50 = load i32* %n, align 4
  %51 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([38 x i8]* @.str, i32 0, i32 0), i32 %50) nounwind
  %52 = load float* %total, align 4
  %53 = fpext float %52 to double
  %54 = load float* %b, align 4
  %55 = fpext float %54 to double
  %56 = load float* %a, align 4
  %57 = fpext float %56 to double
  %58 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([36 x i8]* @.str1, i32 0, i32 0), double %57, double %55, double %53) nounwind
  br label %bb9

bb9:                                              ; preds = %bb8, %bb7
  %59 = call i32 @MPI_Finalize() nounwind
  br label %return

return:                                           ; preds = %bb9
  %retval10 = load i32* %retval
  ret i32 %retval10
}

declare i32 @MPI_Init(i32*, i8***)

declare i32 @MPI_Comm_rank(%struct.ompi_communicator_t*, i32*)

declare i32 @MPI_Comm_size(%struct.ompi_communicator_t*, i32*)

declare i32 @MPI_Recv(i8*, i32, %struct.ompi_datatype_t*, i32, i32, %struct.ompi_communicator_t*, %struct.MPI_Status*)

declare i32 @MPI_Send(i8*, i32, %struct.ompi_datatype_t*, i32, i32, %struct.ompi_communicator_t*)

declare i32 @printf(i8* noalias, ...) nounwind

declare i32 @MPI_Finalize()

define float @Trap(float %local_a, float %local_b, i32 %local_n, float %h) nounwind {
entry:
  %local_a_addr = alloca float, align 4
  %local_b_addr = alloca float, align 4
  %local_n_addr = alloca i32, align 4
  %h_addr = alloca float, align 4
  %retval = alloca float
  %0 = alloca float
  %integral = alloca float
  %x = alloca float
  %i = alloca i32
  %"alloca point" = bitcast i32 0 to i32
  store float %local_a, float* %local_a_addr
  store float %local_b, float* %local_b_addr
  store i32 %local_n, i32* %local_n_addr
  store float %h, float* %h_addr
  %1 = load float* %local_a_addr, align 4
  %2 = call float @f(float %1) nounwind
  %3 = load float* %local_b_addr, align 4
  %4 = call float @f(float %3) nounwind
  %5 = fadd float %2, %4
  %6 = fdiv float %5, 2.000000e+00
  store float %6, float* %integral, align 4
  %7 = load float* %local_a_addr, align 4
  store float %7, float* %x, align 4
  store i32 1, i32* %i, align 4
  br label %bb1

bb:                                               ; preds = %bb1
  %8 = load float* %x, align 4
  %9 = load float* %h_addr, align 4
  %10 = fadd float %8, %9
  store float %10, float* %x, align 4
  %11 = load float* %x, align 4
  %12 = call float @f(float %11) nounwind
  %13 = load float* %integral, align 4
  %14 = fadd float %12, %13
  store float %14, float* %integral, align 4
  %15 = load i32* %i, align 4
  %16 = add nsw i32 %15, 1
  store i32 %16, i32* %i, align 4
  br label %bb1

bb1:                                              ; preds = %bb, %entry
  %17 = load i32* %local_n_addr, align 4
  %18 = sub nsw i32 %17, 1
  %19 = load i32* %i, align 4
  %20 = icmp sge i32 %18, %19
  br i1 %20, label %bb, label %bb2

bb2:                                              ; preds = %bb1
  %21 = load float* %integral, align 4
  %22 = load float* %h_addr, align 4
  %23 = fmul float %21, %22
  store float %23, float* %integral, align 4
  %24 = load float* %integral, align 4
  store float %24, float* %0, align 4
  %25 = load float* %0, align 4
  store float %25, float* %retval, align 4
  br label %return

return:                                           ; preds = %bb2
  %retval3 = load float* %retval
  ret float %retval3
}

define float @f(float %x) nounwind {
entry:
  %x_addr = alloca float, align 4
  %retval = alloca float
  %0 = alloca float
  %return_val = alloca float
  %"alloca point" = bitcast i32 0 to i32
  store float %x, float* %x_addr
  %1 = load float* %x_addr, align 4
  %2 = load float* %x_addr, align 4
  %3 = fmul float %1, %2
  store float %3, float* %return_val, align 4
  %4 = load float* %return_val, align 4
  store float %4, float* %0, align 4
  %5 = load float* %0, align 4
  store float %5, float* %retval, align 4
  br label %return

return:                                           ; preds = %entry
  %retval1 = load float* %retval
  ret float %retval1
}
